package fragments.shopactivity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.widget.EditText;

import com.travel.R;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import fragments.shopadapter.TablayoutFragmentAdapter;

/**
 * Created by Administrator on 2016/10/24.
 */
public class SearchItemActivity extends AppCompatActivity {
    @Bind(R.id.shop_search_ed)
    EditText shopSearchEd;
    @Bind(R.id.shop_tabLayout)
    TabLayout shopTabLayout;
    @Bind(R.id.shop_vp)
    ViewPager shopVp;
    private List<Fragment> list=new ArrayList<>();
    private TablayoutFragmentAdapter adapter;
    private String title[]={"目的地","行程","专题","轻游记","商品",};
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.shop_serach_onclick_activity);
        ButterKnife.bind(this);
        initLists();//添加Fragment
        for (int i=0;i<title.length;i++){
            shopTabLayout.addTab(shopTabLayout.newTab().setText(title[i]));
        }
        shopVp.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(shopTabLayout));

        shopTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                shopVp.setCurrentItem(tab.getPosition());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
            }
            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    private void initLists() {
//        list.add(new jingxuanFragment());
//        list.add(new nvzhuangFragment());
        adapter=new TablayoutFragmentAdapter(getSupportFragmentManager(),list);
        shopVp.setAdapter(adapter);
    }
}
